package com.test.mooan.labama.dialog_boom;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.mooan.labama.R;
import com.test.mooan.labama.adapter_boom.CustomerServiceListAdapter_boom;
import com.test.mooan.labama.bean_boom.config_info_boom.AppShowInfo_boom;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;

public class CustomerServiceDialog_boom extends Dialog {

    public CustomerServiceDialog_boom(@NonNull Context context) {
        super(context);
    }

    private int listHeight = 0;

    private final String pageTag = "DIALOG_CUSTOMER_SERVICE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_customer_service_boom);
        initView();
    }

    @SuppressLint("SetTextI18n")
    private void initView(){

        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        findViewById(R.id.dialog_customer_service_ib_close).setOnClickListener(v -> dismiss());

        TextView hintTv = findViewById(R.id.dialog_customer_service_tv_hint);
        String hint = AppShowInfo_boom.getInstance().gCustomerServiceHint();
        if (!TextUtils.isEmpty(hint)) hintTv.setText(hint);

        ListView listView = findViewById(R.id.dialog_customer_service_lv_list);
        CustomerServiceListAdapter_boom customerServiceListAdapter = new CustomerServiceListAdapter_boom(getContext());
        listView.setAdapter(customerServiceListAdapter);

        ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
        if (listHeight ==0) listHeight = layoutParams.height;
        layoutParams.height = customerServiceListAdapter.getCount()* listHeight;
        listView.setLayoutParams(layoutParams);

    }

    @Override
    public void show() {
        super.show();
        UserInfoHelper_boom.gInstance().addEventPoint(pageTag+"_START");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        UserInfoHelper_boom.gInstance().addEventPoint(pageTag+"_END");
    }

}
